package com.mpsc.spring.demo.sevice.impl;


import com.mpsc.api.bean.RoleInfoEntity;
import com.mpsc.spring.demo.dao.RoleInfoDao;
import com.mpsc.spring.demo.sevice.RoleInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class RoleInfoServiceImpl implements RoleInfoService {

    @Autowired
    private RoleInfoDao roleInfoDao;

    @Override
    @Transactional
    public void saveRoleInfo(RoleInfoEntity role) {
        System.out.println("--------------保存角色之前------------");
        roleInfoDao.saveRoleInfo(role);
        System.out.println("-------------保存角色之后-------------");
        this.updateRoleInfo1();


    }

    private void updateRoleInfo1() {
        RoleInfoEntity role = new RoleInfoEntity();
        role.setId(123L);
        role.setRoleName("roleName123");
        role.setRoleCode("roleCode123");
        roleInfoDao.updateRoleInfoById(role);
        this.updateRoleInfo2();
    }

    private void updateRoleInfo2() {
        RoleInfoEntity role = new RoleInfoEntity();
        role.setId(124L);
        role.setRoleName("roleName1234");
        role.setRoleCode("roleCode1234");
        roleInfoDao.updateRoleInfoById(role);

    }

    private void saveRoleInfo1(RoleInfoEntity role) {
        role.setId(123L);
        roleInfoDao.saveRoleInfo(role);
      //  this.saveRoleInfo2(role);
        throw new RuntimeException("扔出一个异常！");
    }

    private void saveRoleInfo2(RoleInfoEntity role) {
        role.setId(124L);
        roleInfoDao.saveRoleInfo(role);

    }

}
